package cn.yqx.bankshop.goods.controller;

import cn.yqx.bankshop.goods.pojo.BuShoppingCart;
import cn.yqx.bankshop.goods.service.ShoppingCartService;
import cn.yqx.bankshop.result.Result;
import cn.yqx.bankshop.result.ResultCode;
import com.alibaba.fastjson.JSON;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;


@Slf4j
@RestController
@RequestMapping("/api/v1/shopping")
public class ShoppingController {
    private static final String CART_NUM_STR = "cartNum" ;
    @Autowired
    ShoppingCartService shoppingCartService ;

    @RequestMapping(value = "/find_shoppingCarts" ,method = RequestMethod.GET)
    public Object findShoppingCarts (Long userid){
        return null ;
    }

    @RequestMapping(value = "/cartNum" , method = RequestMethod.GET)
    public Object getShoppingCartNum(Long userid){
        Result result ;
        try{
            result = Result.success();
            HashMap<String,Integer> cartNum = new HashMap<String,Integer>(2) ;
            cartNum.put(CART_NUM_STR,shoppingCartService.getShoppingCartNum(userid)) ;
            result.setData(cartNum);
        }catch (Exception e){
            result = Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR) ;
            log.error("error : {} " ,e );
        }


        return  result;
    }
  }
